package com.webjavamai.mailserver;

import java.util.Properties;

import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.AddressException;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
//发送邮件需要安装邮件服务器
public class SendMail {
	
	public static void main(String[] args) {
		Properties props =new Properties();
		Session session=Session.getInstance(props, null);//javax.mail.Session
		props.put("mail.host", "127.0.0.1");
		props.put("mail.transport.protocol", "smtp");
		Message message=new MimeMessage(session);//javax.mail.Message
		try {
			message.setFrom(new InternetAddress("357419543@qq.com"));
			message.setRecipient(Message.RecipientType.CC, new InternetAddress("daohaogun_01@163.com"));//Message.RecipientType.CC抄送
			message.setSubject("你好么？");
			message.setText("javaMail发送测试邮件");
			Transport.send(message);
		} catch (AddressException e) {
			e.printStackTrace();
		} catch (MessagingException e) {
			e.printStackTrace();
		}
	}
}
